﻿using System.Timers;
namespace Controller
{
	public abstract class AbstractPlayer
	{
		protected Timer timer;
		protected bool timerEnabled;
		protected Index[] possibleMoves;

		protected int id;
		public int Id
		{
			get { return id; }
		}

		protected int countPossibleMoves = 0;
		public int CountPossibleMoves
		{
			get { return countPossibleMoves; }
			set { countPossibleMoves = value; }
		}

		public AbstractPlayer(int id, Token token, bool timerEnabled, double timerInterval)
		{
			this.id = id;
			this.token = token;
			this.timerEnabled = timerEnabled;
			timer = new Timer();
			if (timerEnabled)
			{
				timer.Interval = timerInterval;
				timer.Elapsed += new ElapsedEventHandler(MakeMove);
				timer.AutoReset = false;
			}
		}

		protected abstract void MakeMove(object sender, ElapsedEventArgs e);

		protected Token token;

		public Token Token
		{
			get { return token; }
			set { token = value; }
		}

		public void StartMove(ref Index[] possibleMoves)
		{
			this.possibleMoves = possibleMoves;
			if (timerEnabled)
			{
				timer.Enabled = true;
			}
			else
			{
				MakeMove(null, null);
			}
		}

		public double TimerInterval
		{
			set { timer.Interval = value; }
		}
	}
}
